package com.example.maple.ccsclient.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.maple.ccsclient.R;
import com.example.maple.ccsclient.model.PicModel;
import com.example.maple.ccsclient.view.JazzyViewPager;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;


import java.util.List;

/**
 * Created by maple on 2016/8/13.
 */
public class JazzyPagerAdapter extends PagerAdapter {

	List<PicModel> mList = null;
	private android.content.Context mContext;
	JazzyViewPager mJazzyViewPager;
	LayoutInflater mInflater = null;
	public JazzyPagerAdapter(Context context, JazzyViewPager viewPager, List<PicModel> list){
		mContext = context;
		mList = list;
		mJazzyViewPager = viewPager;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View)object);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		 return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {


		View view = mInflater.inflate(R.layout.simple_image,null);
		int width =  mContext.getResources().getDisplayMetrics().widthPixels;
		int height = width;
		view.setLayoutParams(new RelativeLayout.LayoutParams(width,height));
		SimpleDraweeView simpleDraweeView =(SimpleDraweeView) view.findViewById(R.id.my_image_view);

		if(!TextUtils.isEmpty(mList.get(position).getCImages())){
			simpleDraweeView.setImageURI(Uri.parse(mList.get(position).getCImages()));
		}else{
			//设置没有此图片
		}
		container.addView(view);
		mJazzyViewPager.setObjectForPosition(view, position);
		return view;


	}


}
